<!DOCTYPE html>
<title>media controls overlay cast button for autoplay muted element</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../media-controls.js"></script>
<body></body>
<script>
async_test(function(t) {
  t.add_cleanup(function()  {
    internals.settings.setAutoplayPolicy('no-user-gesture-required');
    internals.runtimeFlags.autoplayMutedVideosEnabled = false;
    internals.mediaPlayerRemoteRouteAvailabilityChanged(video, false);
  });

  internals.settings.setAutoplayPolicy('user-gesture-required');
  internals.runtimeFlags.autoplayMutedVideosEnabled = true;

  // Have to create the video so it respects the settings set above.
  var video = document.createElement("video");
  video.muted = true;
  video.autoplay = true;
  video.src = "../content/test.ogv";

  video.onloadedmetadata = t.step_func_done(function() {
    // Pretend we have a cast device
    internals.mediaPlayerRemoteRouteAvailabilityChanged(video, true);
    var button = overlayCastButton(video);
    assert_false(isControlVisible(button),
                 "button should not be visible for videos autoplaying muted");
  });

  document.body.appendChild(video);
}, 'autoplay muted video');
</script>